/*
 * @description: 返回一个函数，用dispatch去包裹 actionCreator的返回值
 */
function bindActionCreator(actionCreator, dispatch) {
  return (...arg) => dispatch(actionCreator(...arg));
}

export default function bindActionCreators(actionCreators, dispatch) {
  if (typeof actionCreators === 'function') {
    return bindActionCreator(actionCreators, dispatch);
  }

  let obj = {};
  for (const key in actionCreators) {
    const actionCreator = actionCreators[key];
    if (typeof actionCreator === 'function') {
      obj[key] = bindActionCreator(actionCreator, dispatch);
    }
  }
  return obj;
}
